home *** CD-ROM | disk | FTP | other *** search
- Path: qiclab.scn.rain.com!qiclab!leonard
- From: leonard@qiclab.scn.rain.com (Leonard Erickson)
- Newsgroups: comp.lang.c++,comp.os.msdos.programmer
- Subject: Re: Timer (0x1C) Interrupt exactly 18.2 seconds?
- Date: 29 Feb 1996 14:13:22 -0800
- Organization: SCN Research/Qic Laboratories of Tigard, Oregon.
- Message-ID: <leonard.825630550@qiclab>
- References: <4givrv$cim@midland.co.nz>
- Reply-To: shadow@krypton.rain.com
- NNTP-Posting-Host: qiclab.scn.rain.com
- X-Newsreader: NN version 6.5.0 #3 (NOV)
-
- lowefam@igrin.co.nz (Jarrod S Lowe) writes:
-
- >I have a C++ Program (on DOS) in which a function is attached to the
- >Timer (0x1C) Interrupt.
-
- >The function has a static int to count the number of times it has been
- >called. Every 'x' calls, It executes another function.
-
- >'x' is 546, which one would expect to result in the function being
- >called every 30 seconds. However, it is called every 29 point
- >something seconds. Over 5 minutes you can see it has drifted. If I had
- >one to 'x' (now 547) it is called every 30 point something seconds -
- >the same problem in reverse.
-
- Take a look at a motherboard. You'll find a crystal marked 14.31818 MHz.
- This is used for several things. Divided by 4 it gives the 3.579MHz
- "colorburst" frequency needed by CGA cards. Divided by 3 it gives the 4.77
- MHz clock used by the original PC & XT.
-
- Now, take that 4.77 MHz (actually 4.772726666... MHz). Divide it by 2^18.
- (262,144). That gives you the "clock tick". And as you can see, it *isn't*
- 18.2 Hz. It's 18.20650736... Hz.
-
- So I'd advise using (14318180/3) shr 18 instead of 18.2. Or to put it
- another way, there are 1,573,042 ticks in a day. And you want your function
- called 2880 times in that period. Unfortunately, the *only* common factor
- between those numbers is 2. So you'd use 786521/1440 as your counter value.
- Messy.
-
- If you can afford the RAM, it might be best to just create a table with
- 2880 entries, and compare them to the longint clocktick counter in low
- RAM. That'd eat up 11 1/4 k of RAM.
-
- Otherwise you live with the drift.
-
- --
- Leonard Erickson leonard@qiclab.scn.rain.com
- (aka Shadow) shadow@krypton.rain.com (preferred)
- FIDO: 1:105/51 Leonard.Erickson@f51.n105.z1.fidonet.org
-